// 注册
Vue.component('one_back_list', {
	props: ['parent_data'],
	template: '<div class="back_detail">\
						<button type="button" class="btn btn-base back_list_btn" @click="hide">返回列表</button>\
						<div class="list">\
							<li class="title">共<span>{{replycount}}</span>条回复</li>\
							<div class="back_list">\
								<div class="one_back cursor" v-for="(item,index) in newsReplyss">\
									<div class="one_content"  @click.stop="replyReplyShow($event,item)">\
										<div class="icon">\
											<img  :src="item.HeadImage ? (host+item.HeadImage) : \'imgs/icon.jpg\'" onerror="globalData.utils.imgLoadErr(event)" alt="" />\
										</div>\
										<div class="right my_flex my_flex_col">\
											<span>{{item.Creator}}</span>\
											<span v-html="item.Content"></span>\
											<div>\
												<span>{{item.CreateTimeText}}</span>\
											</div>\
										</div>\
										<div class="icons">\
											<li class="my_flex my_flex_center"><img src="imgs/community/back.png"  alt="" />{{item.ReplyCount}}</li>\
										</div>\
									</div>\
									<div class="back_other" @click.stop="">\
										<form class="form-horizontal">\
											<div class="form-group my_tips">\
												<textarea placeholder="请输入评论内容" name="content" v-model="content" class="form-control" rows="4"></textarea>\
											</div>\
											<button type="button" style="width: auto;" class="btn btn-base" @click="reply(item.ID)">发 表</button>\
										</form>\
									</div>\
								</div>\
								<!--<change-page :current_page="page.pageIndex" :page_size="page.pageSize" :page_total="page.pageTotal" @page-change="getPageUserCommentForApp"></change-page>-->\
							</div>\
						</div>\
					</div>',
	data: function() {
		return {
			host:globalData.constParam.url.baseUrl+'/',
			url: {
				getPageUserCommentForApp: '/api/Forum/GetPageUserCommentForApp', //回复的回复
				reply:'/api/Forum/AddForum',
			},
			page: {
				pageIndex: 1,
				pageSize: 10,
				pageTotal: 0
			},
			newsReplyss:[],
			replycount:0,
			content:""
		}
	},
	watch: {
		id: function(val, oldval) {
			console.log(val, oldval)
		}
	},
	mounted: function() {
		this.getPageUserCommentForApp(this.page.pageIndex, this.page.pageSize);
		$(document).on('click',function(){
			$('.back_other').slideUp()
		})
		var top = $(document).scrollTop() + 100 + "px"
		$(".back_detail").css({"top":top})
		$(".mask").show()
	},
	methods: {
		//对回复的回复
		replyReplyShow: function(ev) {
			var dom = $(ev.target);
			console.log(dom)
			while(!dom.hasClass('one_content')){
				dom = dom.parent();
			}
			var sibling = dom.next('.back_other')
			if(sibling.css('display') == 'block'){
				sibling.slideUp();
			}else{
				sibling.slideDown();
			}
		},
		hide: function() {
			this.parent_data.isShow = false
			$(".mask").hide()
		},
		//回复的回复列表
		getPageUserCommentForApp: function(curPage, pageSize) {
			var that = this;
			var data = {
				PageIndex: curPage,
				PageSize: pageSize,
				ID: that.parent_data.replyId
			};
			globalData.ajaxPost(this.url.getPageUserCommentForApp, data, function(res) {
				var d = res.data;
				d = globalData.utils.notNullDefaulst(d, []);
				globalData.utils.page(that, curPage, res.count);
				that.replycount=res.count;
				for(var i=0;i<d.length;i++){
					d[i].HeadImage=globalData.utils.imagePrefix(d[i].HeadImage);
				}
				that.newsReplyss = d;
				console.log(d)
			});
		},
		//回复
		reply:function(id,num){
			var b = globalData.userIsLogin(this);
			var that = this
			if(!b)
				return;
			if(this.content.length<1){
				$("#alert").css({"z-index":10000}).modal()
				$('#alert p').text('请输入评论内容')
				return;
			}
			globalData.ajaxPost(this.url.reply,{ReplyId:id,Title:'',Content:this.content},function(res){
				if(!res.suc){
					globalData.utils.alert(res.msg);
					return;
				}
				$(document).click();
				that.content="";
				that.getPageUserCommentForApp(that.page.pageIndex, that.page.pageSize);
			});
		},
	}
})